home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / graphics / picsize / picsize.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  123 lines

  1. /* :ts=3
  2. ** determines picture information using datatypes
  3. **
  4. ** written & © Ralph Reuchlein 1999
  5. */
  6.  
  7.  
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <datatypes/pictureclass.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14. #include <proto/datatypes.h>
  15.  
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21.  
  22.  
  23. #define  TEMPLATE    "PICTURE=PIC/A,"\
  24.                      "WIDTH/S,"\
  25.                      "HEIGHT/S,"\
  26.                      "SIZE/S,"\
  27.                      "DEPTH/S,"\
  28.                      "FORMAT/S,"\
  29.                      "FULL/S"
  30. enum
  31. {
  32.    OPT_PIC,
  33.    OPT_WIDTH,
  34.    OPT_HEIGHT,
  35.    OPT_SIZE,
  36.    OPT_DEPTH,
  37.    OPT_FORMAT,
  38.    OPT_FULL,
  39.  
  40.    OPT_COUNT
  41. };
  42. #define  OPTS_PIC    (STRPTR)opts[OPT_PIC]
  43. #define  OPTS_WIDTH  (opts[OPT_WIDTH]==-1)
  44. #define  OPTS_HEIGHT (opts[OPT_HEIGHT]==-1)
  45. #define  OPTS_SIZE   (opts[OPT_SIZE]==-1)
  46. #define  OPTS_DEPTH  (opts[OPT_DEPTH]==-1)
  47. #define  OPTS_FORMAT (opts[OPT_FORMAT]==-1)
  48. #define  OPTS_FULL   (opts[OPT_FULL]==-1)
  49.  
  50.  
  51. void error(STRPTR,...);
  52. STRPTR basename(STRPTR);
  53.  
  54.  
  55.  
  56. void main(UWORD argc, STRPTR argv[])
  57. {
  58.    static long             opts[OPT_COUNT];
  59.    struct RDArgs          *rdargs;
  60.    Object                 *picobj;
  61.    struct BitMapHeader    *bmhdr;
  62.    struct DataType        *dt;
  63.  
  64.    /* parse parameters */
  65.    if(rdargs = ReadArgs(TEMPLATE, opts, NULL))
  66.    {
  67.       if (picobj=NewDTObject(OPTS_PIC,PDTA_FreeSourceBitMap,TRUE,TAG_DONE))
  68.       {
  69.          GetDTAttrs(picobj,PDTA_BitMapHeader,&bmhdr,DTA_DataType,&dt,TAG_DONE);
  70.          while(TRUE)
  71.          {
  72.             if (OPTS_WIDTH && OPTS_HEIGHT)
  73.             {
  74.                printf("%ux%u\n",bmhdr->bmh_Width,bmhdr->bmh_Height); break;
  75.             }
  76.             if (OPTS_WIDTH)   { printf("%u\n",bmhdr->bmh_Width); break;}
  77.             if (OPTS_HEIGHT)  { printf("%u\n",bmhdr->bmh_Height); break;}
  78.             if (OPTS_SIZE)    { printf("%ux%ux%u\n",bmhdr->bmh_Width,bmhdr->bmh_Height,bmhdr->bmh_Depth); break;}
  79.             if (OPTS_DEPTH)   { printf("%u\n",bmhdr->bmh_Depth); break;}
  80.             if (OPTS_FORMAT)  { printf("%.99s\n",dt->dtn_Header->dth_Name); break;}
  81.             printf("%-30s\t%ux%ux%u, %.99s\n",basename(OPTS_PIC),bmhdr->bmh_Width,bmhdr->bmh_Height,bmhdr->bmh_Depth,dt->dtn_Header->dth_Name);
  82.             break;
  83.          }
  84.          DisposeDTObject(picobj);
  85.       }
  86.       else
  87.       {
  88.          error("Couldn't generate new datatype object from '%s'!",OPTS_PIC);
  89.       }
  90.  
  91.       FreeArgs(rdargs);
  92.    }
  93.    else
  94.    {
  95.       error("Usage:\n%s %s",argv[0],TEMPLATE);
  96.    }
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. void error(STRPTR fmt,...)
  105. {
  106.    va_list args;
  107.    va_start(args,fmt);
  108.    vfprintf(stderr,fmt,args);
  109.    vfprintf(stderr,"\n",NULL);
  110.    va_end(args);
  111. }
  112.  
  113. STRPTR basename(STRPTR fullname)
  114. {
  115.    register WORD i;
  116.    for (i=(strlen(fullname)-1);i>=0;i--)
  117.    {
  118.       if (fullname[i]=='/')   return(&fullname[i+1]);
  119.       if (fullname[i]==':')   return(&fullname[i+1]);
  120.    }
  121.    return(fullname);
  122. }
  123.